#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}
bool Widget::event(QEvent *event)
{
    QMouseEvent *e = static_cast<QMouseEvent *>(event);

    if(event->type()==QEvent::MouseMove){
        this->point_.append(e->pos());
        this->update();
    }
    else if(event->type()==QEvent::MouseButtonRelease){
        points_.append(point_);
        point_.clear();
    }
    if(event->type()==QEvent::Paint){
        QPainter painter(this);
        QPen pen(QColor(255,0,0));
        pen.setWidth(3);
        painter.setPen(pen);
        painter.drawPolyline(QPolygon(point_));
        for(auto p:this->points_){
            painter.drawPolyline(QPolygon(p));
        }
    }
    return QWidget::event(event);
}

Widget::~Widget()
{
    delete ui;
}

